package com.situ.mall.common.util;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
//请求工具
public class RequestUtil {

    private static final String CURRENT = "currentUser";
    //获取当前请求的一个途径 不用从controller接参数再往service导
    public static HttpServletRequest getRequest(){
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }
    //获取session
    public static HttpSession getSession(){
        return getRequest().getSession();
    }

    public static void setCurrent(Object u){
        getSession().setAttribute(CURRENT,u);
    }

    public static Object getCurrent(){
        return getSession().getAttribute(CURRENT);
    }
}
